    var newrow;
    var isProperty = false;
    var newbutcol;
    var noOfTextCols;
    var noOfButtonCols = 2;
    //var MyBrowser = 0;    // MyBrowser = 1  if IE
                          // MyBrowser = 2  if Firefox Mozilla,Opera 8.0+, Safari
                          // MyBrowser = 3  if not supported
    var xmlHttp;
    var key;
    var bar_color = 'gray';
    var span_id = "block";
    var clear = "&nbsp;&nbsp;&nbsp;"
    var old_table_data;
    var counter = 0;
    

    var behavior;
    var objname;
    var objcounter = 0;
    var returndata;

function getCounter()
{
	//alert("i'm in get counter");
	return objcounter;
}

function NewFun(object)
{
	alert("I'm in new "+object.name);
	
	objname = object.name.split("_")[0];
	alert(objname);
	
	if(window.opener != null)
	{
		alert("window has an opener");
		objcounter = window.opener.getCounter();
	}
    
	alert("before"+objcounter);
	var windowname = objname+"_"+objcounter;
	
	alert(windowname);
	objcounter = objcounter + 1;
	alert("after"+objcounter);
	
	mywindow = window.open(objname+".html",windowname,"menubar=0,resizable=0,width=500,height=350,scrollbars=1");	
	mywindow.href = objname+".html";
	mywindow.moveTo(350,250);
	return false;
}

function setData(mydata)
{
	alert("I'm in set data"+mydata);
	alert(objname);	
	document.getElementById(objname).value = mydata;
}

function setBehavData(mydata)
{
	alert("I'm in set data"+mydata);
	alert(behavior);	
	document.getElementById(behavior).value = mydata;
}

function NewBehave()
{
	mywindow = window.open(behavior+".html","mywindow","menubar=0,resizable=0,width=500,height=350,scrollbars=1");
	//mywindow.href = behavior+".html";
	mywindow.moveTo(350,250);
	return false;
}

function setBehavior(behav)
{
	behavior = behav.value;
	alert(behavior);
}

function setReturn(id)
{
	//alert("I'm in set "+id);
	var temp = id.value;
	returndata = temp;
	//alert(returndata);
	return true;
}

function ReturnValues()
{
	alert("I'm in return  "+returndata);
	alert("opener window is is"+self.opener.parent.frames['DetailsFrame'].document.forms[0]..name);
	//window.parent.opener;	
	//self.opener.parent.frames['DetailsFrame'].window.document.setData(returndata);
	self.close();
	return false;
}



//------------------------------------------------------------------------------------------


	function cloneRow(rownum)
	{		
		//alert("roe toclone is "+rownum);
	    // Declare variables 
	    var elements, templateRow, rownum, rowCount, row, className, newRow, element;
	    var i, s, t;
	    
	    // Get and count all "tr" elements with class="row".    The last one will
	     // be serve as a template. 
	    if (!document.getElementsByTagName)
	        return false; // DOM not supported 
	    elements = document.getElementsByTagName("tr");
	    templateRow = null;
	    rowCount = 0;
	    for (i = 0; i < elements.length; i++) {	       
	       row = elements.item(i);
	       /* // Get the "class" attribute of the row. 
	        className = null;
	        if (row.getAttribute)
	            className = row.getAttribute('class')
	        if (className == null && row.attributes) {    // MSIE 5
	            // getAttribute('class') always returns null on MSIE 5, and
	            // row.attributes doesn't work on Firefox 1.0.    Go figure. 
	            className = row.attributes['class'];
	            if (className && typeof(className) == 'object' && className.value) {
	                // MSIE 6
	                className = className.value;
	            }
	        } 
	        
	        // This is not one of the rows we're looking for.    Move along. 
	        if (className != "row_to_clone")
	            continue;*/
	        
	        // This *is* a row we're looking for.
	         if(i == rownum)
	         {		 	
			 	row.cells[0];
	         	// set id
				var id = elements.length+1;
				alert("id is field_"+id);
				row.setAttribute("id","field_"+id);
				row.setAttribute("value","field_"+id);
				// 
	         	templateRow = row;
       		 }
	        rowCount++;
	    }
	    
	    if (templateRow == null)
	        return false; // Couldn't find a template row. 
	    
	    // Make a copy of the template row 
	    newRow = templateRow.cloneNode(true);
	
	    // Change the form variables e.g. price[x] -> price[rowCount] 
	    elements = newRow.getElementsByTagName("input");
	    for (i = 0; i < elements.length; i++) {
	        element = elements.item(i);
	        s = null;
	        s = element.getAttribute("name");
	        if (s == null)
	            continue;
	        t = s.split("[");
	        if (t.length < 2)
	            continue;
	        s = t[0] + "[" + rowCount.toString() + "]";
	        element.setAttribute("name", s);
	        element.value = "";
	    }
	    
	    // Add the newly-created row to the table 
	    templateRow.parentNode.appendChild(newRow);
	    return true;
  	}


    function createXMLHttpRequestObject() 
    {
        try
        {
            // Firefox, Opera 8.0+, Safari
            xmlHttp=new XMLHttpRequest();
            MyBrowser = 2;
        }
        catch (e)
        {
            // Internet Explorer
            try
            {
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                MyBrowser = 1;
            }
            catch (e)
            {
                try
                {
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                    MyBrowser = 1;
                }
                catch (e)
                {
                    alert("Your browser does not support AJAX!");
                    MyBrowser = 0;
                    return false;
                }
            }
        }
    }
    
    function callAjax()
    {
        createXMLHttpRequestObject();            
        xmlHttp.onreadystatechange=function()
        {
            if(xmlHttp.readyState==4)
            {
                updateTable(xmlHttp);
            }
        }

        xmlHttp.open("GET","featchtranaction?tid="+tid,true);
        xmlHttp.send(null);
    }

    function chk(form1)
    {
            var f1 = form1;
                        
            if(f1.username.value=="" || f1.username.value==" ") 
            {     
              //alert("Invalid username");
              f1.username.focus();
              return false;       
            }
             if(f1.password.value=="" || f1.password.value==" ") 
            {     
              //alert("Invalid password");
              f1.password.focus();
              return false;       
            }
            
            return true;
       }

	function copyRow(id,rownum)
	{
		var temp = document.getElementById(id);
		var myrow = temp.rows[rownum];
		alert(myrow);
		var len = myrow.cells.length;
		alert(len);
		var newrownum = rownum+1;
		alert("newrownum  "+newrownum);
		var mynewrow = temp.insertRow(newrownum);
		alert(mynewrow);
		
		for(var i=0;i<len;i++)
		{
			alert("I'm in for");
			var myCell = mynewrow.insertCell(i);
			alert("inserted  cell in new row "+myCell);
			
			if(myrow.cells[i].hasChildNodes() == true)
          		{
				alert("the cell has child nodes");
				var e1 = myrow.cells[i].firstChild;
				alert("e1 "+e1);
				var e2 = e1;
				myCell.appendChild(e2);
				alert(myCell.firstChild);
				//alert(myCell);
			}
		}		
	}
    

       
    function insertRow(id,buttonrow,buttoncol)
    {   
        //alert("I'm in insert");
        //alert(document.getElementById(id).innerHTML);
        
        var temp = document.getElementById(id);
        //alert("Temp is  "+temp);
        
        var rows = temp.rows.length;
        //alert("No of rows  "+rows);
        
        noOfTextCols = temp.rows[buttonrow].cells.length-2;
        //alert("noOfTextCols is    "+noOfTextCols);
                
        //alert(buttonrow+" , "+buttoncol);
        var newbutrow = buttonrow-1+2;
         
        newrow = temp.insertRow(newbutrow);
        //alert("new row inserted at   "+newbutrow);
        
        createRow(id,buttonrow,buttoncol,"Add");
        
        var newrows = temp.rows.length;
        //alert("No of newrows  "+newrows);
        
        for(var i = buttonrow-3+5;i<=newrows;i++)
        {   
            //alert("The val of i in for is   "+i);        
            //alert("Buttonrow is   "+buttonrow);
            //alert("buttoncol  is  "+buttoncol);
            
            getButtonColNum(id,i,"Add");
            //alert("newbutcol  is  "+newbutcol);
            
            //alert("deleting row at  "+i);
            //temp.deleteRow(i);
            
            //newrow = temp.insertRow(i);
            //createRow(id,i-1,newbutcol,"Add");
            
            updateRow(id,i,newbutcol,"Add");
        }
        
    }    
    
    function updateRow(id,rownum,buttoncol,buttonval)
    {
        //alert("inside updateRow  ");
        //alert("updating row  "+rownum);
        
        //alert("id-"+id+"   rownum-"+rownum+"   buttoncol-"+buttoncol+"  param-"+buttonval);
        
        var temp = document.getElementById(id);
        var cols = temp.rows[rownum].cells.length
        
        for(var i=0;i < cols;i++)
        {
          //alert(" In for, i is  "+i);
          
          if(temp.rows[rownum].cells[i].hasChildNodes() == true)
          {              
              //alert("cell has child node");
              var e1 = temp.rows[rownum].cells[i].firstChild;
              var celldata = "";
              var colnum = 0;
              var ButtonIdName = "";
              
              if(e1.type == 'button')
              {
                    //alert("setting button attribute");
                    if(e1.value == "Add")
                    {
                            //alert("Button is Add  ");
                                           
                            if(e1.id != undefined)
                            {
                               //alert("setting add button id  ");
                               celldata = e1.id;
                               //alert("Cell data in id  "+celldata);
                               colnum = celldata.split("_")[1];
                               //alert("Col num is "+colnum);
                               e1.removeAttribute('id');
                               ButtonIdName = "button"+rownum+"_"+colnum;
                               //alert("ButtonIdName   "+ButtonIdName);
                               //alert("new ButtonIdName is   "+ButtonIdName);
                               e1.setAttribute('id',ButtonIdName);   
                               //alert("id  is    "+e1.getAttribute("id"));
                            }                      
                            if(e1.name != undefined)
                            {
                              //alert("setting add button name  ");
                              celldata = e1.name;
                              //alert("Cell data is "+celldata);
                              colnum = celldata.split("_")[1];
                              //alert("Col num is "+colnum);
                              e1.removeAttribute('name');
                              ButtonIdName = "button"+rownum+"_"+colnum;
                              //alert("ButtonIdName   "+ButtonIdName);
                              //alert("new ButtonIdName is   "+ButtonIdName);
                              e1.setAttribute('name',ButtonIdName);
                              //alert("name  is    "+e1.getAttribute("name"));
                            }                                
                            if ((!document.all)&&(document.getElementById))
                            {
                                //alert("Browser is Firefox");
                                //alert("setting add onclick attribute");
                                //alert("onclick att is "+e1.getAttribute("onclick"));
                                e1.removeAttribute("onclick");
                                //alert("onclick removed & is "+e1.getAttribute("onclick"));
                                //var temp = document.getElementById(ButtonIdName);
                                //alert("temp is     "+temp);
                                e1.setAttribute("onclick","insertRow('"+id+"',"+rownum+","+colnum+")");
                                //alert("now onclick att is "+e1.getAttribute("onclick"));
                            }         
                            if ((document.all)&&(document.getElementById))
                            {           
                                  //alert("Browser is IE");
                                 // alert("setting add onclick attribute");
                                  //alert("onclick att is "+e1.getAttribute("onclick"));
                                  e1.removeAttribute('onClick');
                                  //alert("onclick removed");
                                  e1onClick = document.createAttribute('onClick');
                                  e1onClick.value = "insertRow('"+id+"',"+rownum+","+colnum+")";
                                  e1.setAttributeNode(e1onClick);
                                  //alert("onclick attribute has been set to   "+e1.getAttribute('onClick'));
                            }
                    }
                    else if(e1.value == "Del")
                    {               
                        //alert("Button is Del  ");
                        var colnum;
                      
                          if(e1.id != undefined)
                          {
                              //alert("setting Del button id  ");
                              celldata = e1.id;
                              //alert("Cell data is "+celldata);
                              colnum = celldata.split("_")[1];
                              //alert("Col num is "+colnum);
                              e1.removeAttribute('id');
                              ButtonIdName = "button"+rownum+"_"+colnum;
                              //alert("ButtonIdName   "+ButtonIdName);
                              //alert("new ButtonIdName is   "+ButtonIdName);
                              e1.setAttribute('id',ButtonIdName);    
                              //alert("id  is    "+e1.getAttribute("id"));
                          }
                          if(e1.name != undefined)
                          {
                              //alert("setting Del button id  ");
                              celldata = e1.name;
                              //alert("Cell data is "+celldata);
                              colnum = celldata.split("_")[1];
                              //alert("Col num is "+colnum);
                              e1.removeAttribute('name');
                              ButtonIdName = "button"+rownum+"_"+colnum;
                              //alert("ButtonIdName   "+ButtonIdName);
                              //alert("new ButtonIdName is   "+ButtonIdName);
                              e1.setAttribute('name',ButtonIdName);
                              //alert("name  is    "+e1.getAttribute("name"));
                          }                          
                          if ((!document.all)&&(document.getElementById))
                          {
                              //alert("Browser is Firefox");
                              //alert("setting del onclick attribute");                
                              //alert("onclick att is "+e1.getAttribute("onclick"));
                              e1.removeAttribute("onclick");
                              //alert("onclick removed & is "+e1.getAttribute("onclick"));   
                              //var temp = document.getElementById(ButtonIdName);
                              //alert("temp is     "+temp);
                              e1.setAttribute("onclick","removeRow('"+id+"',"+rownum+","+colnum+")");
                              //alert("now onclick att is "+e1.getAttribute("onclick"));
                          }
                          if ((document.all)&&(document.getElementById))
                          {
                              //alert("Browser is IE");
                              //alert("setting del onclick attribute");
                              //alert("onclick att is "+e1.getAttribute("onclick"));
                              e1.removeAttribute('onClick');
                              alert("onclick removed");
                              e1onClick = document.createAttribute('onClick');   
                              e1onClick.value = "removeRow('"+id+"',"+rownum+","+colnum+")";   
                              e1.setAttributeNode(e1onClick);                            
                              //alert("onclick attribute has been set to   "+e1.getAttribute('onClick'));
                          }
                    }
              }
              else if(e1.type == 'text')
              {
                      //alert("setting text attribute");
                      
                      if(e1.id != undefined)
                      {
                          //alert("setting text id  ");
                          celldata = e1.id;
                          //alert("Cell data is "+celldata);
                          colnum = celldata.split("_")[1];
                          //alert("Col num is "+colnum);
                          e1.removeAttribute('id');
                          var TextIdName = "text"+rownum+"_"+colnum;
                          //alert("new TextIdName is   "+TextIdName);
                          e1.setAttribute('id',TextIdName);                     
                      }
                      if(e1.name != undefined)
                      {
                          //alert("setting text name  ");
                          celldata = e1.name;
                          //alert("Cell data is "+celldata);
                          colnum = celldata.split("_")[1];
                          e1.removeAttribute('name');
                          var TextIdName = "text"+rownum+"_"+colnum;
                          //alert("new TextIdName is   "+TextIdName);
                          e1.setAttribute('name',TextIdName);
                      }               
              }
              else
              {
                  //alert("The element is neither button nor input text ");                  
              }
          }
          else
          {
             //alert("Cell is empty");
          }
        }
    }
    
    function getButtonColNum(id,rownum,buttonval)
    {
        //alert("I'm in getButtonColNum()  ");
        //alert("id  "+id+" rownum "+rownum+" buttonval "+buttonval);
        
        var temp = document.getElementById(id);
        //alert(temp);
        
        var cols = temp.rows[rownum].cells.length;
        //alert("No of cols in row "+rownum+"  are  "+cols);
        
        //var childnodes = temp.rows[2].cells[i].childNodes;
        //alert("childnodes   "+childnodes);
        
        for(var i=0;i < cols;i++)
        {
          //alert(" In for i is  "+i);
          
          if(temp.rows[rownum].cells[i].hasChildNodes() == true)
          {
              //alert("Cell "+i+" has child node");
              if(temp.rows[rownum].cells[i].firstChild.getAttribute('type') == 'button' && temp.rows[rownum].cells[i].firstChild.getAttribute('value') == buttonval)
              {
                  //alert("Cell "+i+" has a button inside it with val  "+buttonval);
                  var e1 = temp.rows[rownum].cells[i].firstChild;
                  //alert("e1 name is "+e1.name);
                   var celldata = "";
                   
                  if(e1.name == undefined)
                  {
                     celldata = e1.id;
                  }
                  else
                  {
                    celldata = e1.name;
                  }
                                  
                  //alert("Cell data is "+celldata);
                  var colnum = celldata.split("_")[1];
                  if(buttonval == 'Add')
                  {
                      newbutcol = colnum-1;
                  }
                  else
                  {
                      newbutcol = colnum;
                  }
                  //alert("New button col is "+newbutcol);
                  break;
              }
          } 
          else
          {
            //alert("Cell  "+i+" has no childs");
          }
        }    
    }
    
    function createRow(id,rownum,buttoncol,param)
    {
        //alert("Inside createRow function");
        //alert("id   "+id+"  rownum  "+rownum+"buttoncol    is "+buttoncol+"   param  "+param);
        var TextFrom = 0;
        var ButtonFrom = 0;
        
        var temp = document.getElementById(id);
        var cols = temp.rows[rownum].cells.length;
        //alert("no of cols are  "+cols);
        
        if(param=='Add')
        {
          //alert("param is add   ");
          TextFrom = buttoncol-1;
          ButtonFrom = buttoncol-1+2;          
        }
        else
        {
          //alert("param is del   ");
          TextFrom = buttoncol-3;
          ButtonFrom = buttoncol;          
        }        
        var myCell = "";        
        var buttoncounter = 0;
        
        //alert("TextFrom   "+TextFrom);
        //alert("ButtonFrom   "+ButtonFrom);
        
        for(var i = 0; i < cols-1+2; i++)
        {          
              //alert("i--"+i+"  noOfTextCols--"+noOfTextCols+"  TextFrom--"+TextFrom);
              if(i <= noOfTextCols && i >= TextFrom )
              {
                      //alert("inserting text at  "+i+" col");

                      var textNameId = "text"+(rownum+1)+"_"+i;
                      //alert("textNameId   "+textNameId);

                      myCell = newrow.insertCell(i);

                      var el = document.createElement('input');

                      el.setAttribute("type" , "text");
                      el.setAttribute("name" ,textNameId);
                      el.setAttribute("id", textNameId);

                      //alert("text type is set   "+el.getAttribute("type"));

                      if ((!document.all)&&(document.getElementById))
                      {
                          el.setAttribute("onkeypress","setData(this,this.value)");
                          //alert("Created att onkeypress text1  ");
                      }                   
                      if ((document.all)&&(document.getElementById))
                      {               
                           el["onkeypress"]=new Function("setData(this,this.value)");
                           //alert("Created att onkeypress text1"+e1.getAttribute('onkeypress'));
                      }

                      myCell.appendChild(el);
              }   
              else if(i >= ButtonFrom)
              {                  
                      //alert("inserting button at   "+i+" col");                  

                      var newbutrow = rownum-1+2;

                      myCell = newrow.insertCell(i);

                      if(buttoncounter == 0)
                      {
                          myCell.setAttribute("align","right");
                      }
                      else
                      {
                          myCell.setAttribute("align","left");
                      }
                      var el = document.createElement('input');

                      var buttonIdName = 'button'+newbutrow+"_"+i;
                      //alert("buttonIdName   "+buttonIdName);

                      el.setAttribute("type", "button");
                      //alert("button type is set   "+el.getAttribute("type"));
                      el.setAttribute("name",buttonIdName);
                      el.setAttribute("id", buttonIdName);
                      

                      if ((!document.all)&&(document.getElementById))
                      {
                          if(buttoncounter == 0)
                          {
                              el.setAttribute("value", "Add");
                              el.setAttribute("onclick","insertRow('"+id+"',"+newbutrow+","+i+")");
                              //alert("Created att onclick but 1");
                          }
                          else
                          {
                              el.setAttribute("value", "Del");
                              el.setAttribute("onclick","removeRow('"+id+"',"+newbutrow+","+i+")");
                              //alert("Created att onclick but 2");
                          }                        
                      }                   
                      if ((document.all)&&(document.getElementById))
                      {               
                          if(buttoncounter == 0)
                          {
                              el["onclick"]=new Function("insertRow('"+id+"',"+newbutrow+","+i+")");
                              //alert("Created att onclick but 1");
                          }
                          else
                          {
                              el["onclick"]=new Function("removeRow('"+id+"',"+newbutrow+","+i+")");
                              //alert("Created att onclick but 2");
                          }
                      }

                      myCell.appendChild(el);
                      buttoncounter = 1;
              }
              else
              {
                  //alert("Inserting blank  at "+i+"   col");
                  myCell = newrow.insertCell(i);           
              }
        }
        
        //alert("Outside createRow function");
    }           
    
    function removeRow(id,buttonrow,buttoncol)
    {
      //alert("I'm in removeRow");
      //alert("Button row is   "+buttonrow);
      var temp = document.getElementById(id);    
      
      if(buttonrow > 0)
      {
          //alert("Deleteing row at position  "+buttonrow);
          temp.deleteRow(buttonrow);
          
          var newrows = document.getElementById(id).rows.length;
          //alert("no of rows now are  "+newrows);
          
          if(buttonrow != newrows-1)
          {
              for(var i=buttonrow; i <= newrows;)
              {
                        //alert("In for i is  "+i);

                        checkForProperty(id,i,buttoncol);

                        if(counter == 0)
                        {
                            //alert("Counter is 0");
                            
                            if(isProperty == true)
                            {
                                //alert("property is true");
                                //alert("The row will be deleted "+i);
                                temp.deleteRow(i);
                            }
                            else
                            {
                                //alert("property is false");
                                counter = 1;
                                updateRow(id,i,buttoncol,"Del");
                                i++;
                            }
                        }
                        else
                        {
                            
                            //alert("Counter is 1");
                            //alert("Following row will be updated "+i);
                            updateRow(id,i,buttoncol,"Del");
                            i++;
                        }
              }
              
              counter = 0;10.
              
          }
          
      }
      else
      {
          //alert("Can't delete. There is only one object.");
      }       
        
        return false;
    }   
    
    function checkForProperty(id,buttonrow,buttoncol)
    {
        //alert("Inside check for property");
        //alert("id   "+id+"   buttonrow "+buttonrow+"   buttoncol  "+buttoncol);
        
        var temp = document.getElementById(id);
        //alert("Temp is   "+temp);
        
        newbutcol = 0;
        getButtonColNum(id,buttonrow,"Del");
        //alert("Now new but col is   "+newbutcol);
        
        if(buttoncol < newbutcol)
        {
            isProperty = true;
            //alert("isPropety  is set true");
        }
        else
        {
            isProperty = false;
            //alert("isPropety  is set false");
        }
    }
    
    function setData(id,idval)
    {
      //alert("Inside setData()  ");
      var temp = document.getElementById(id);
      temp.value = temp.value+idval;
    }
    
    function setMaxRowCol()
    {
        //alert("I'm in setmaxRowCol()");
        var maxrow = document.getElementById("Table1").rows.length-1;
        //alert("maxrow is  "+maxrow);
        
        document.form1.RowsHidden.value = maxrow;
        //alert("RowsHidden.text is  "+document.form1.RowsHidden.text);
        
        var maxcol = 0;
        
        for(var i=0;i <=maxrow;i++)
        {
            //alert("I'm in for");
            var cols = document.getElementById("Table1").rows[i].cells.length-1;
            //alert("cols is "+cols);
            
            if(maxcol < cols)
            {
                maxcol = cols;
                //alert("maxcols is set to cols");
            }
        }
        
        document.form1.ColsHidden.value = maxcol;
        //alert("ColsHidden.text is  "+document.form1.ColsHidden.text);
        
        //alert("MAXROWS  "+document.form1.RowsHidden.value+"    MAXCOLS  "+document.form1.ColsHidden.value);    
        return true;
    }
       
        
